package com.atguigu.process.service.impl;


import com.atguigu.model.process.ProcessTemplate;
import com.atguigu.model.process.ProcessType;
import com.atguigu.process.mapper.OaProcessTypeMapper;
import com.atguigu.process.service.OaProcessTemplateService;
import com.atguigu.process.service.OaProcessTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 审批类型 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2023-06-05
 */
@Service
public class OaProcessTypeServiceImpl extends ServiceImpl<OaProcessTypeMapper, ProcessType> implements OaProcessTypeService {
    @Autowired
    private OaProcessTemplateService processTemplateService;

    @Override
    public Object findProcessType() {
        //1.查询所有审批分类
        List<ProcessType> processTypeList = baseMapper.selectList(null);
        //2.遍历返回的审批分类，得到每个审批分类的id，去查询对应的审批模板
        for (ProcessType processType:processTypeList) {
            Long id = processType.getId();

            LambdaQueryWrapper<ProcessTemplate> wrapper=new LambdaQueryWrapper<>();
            wrapper.eq(ProcessTemplate::getProcessTypeId,id);
            List<ProcessTemplate> processTemplateList = processTemplateService.list(wrapper);
            //3.将得到的审批模板，封装到审批分类对象
            processType.setProcessTemplateList(processTemplateList);
        }

        return processTypeList;
    }
}
